package com.stockz.equity.charting.view.widget;

import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

import com.stockz.equity.charting.event.EventPublisher;
import com.stockz.equity.charting.event.RepaintStockChartPanelEvent;
import com.stockz.equity.charting.view.StockChart;
import com.stockz.equity.charting.view.StockChartView;
import com.stockz.equity.charting.view.toolbar.DrawingToolbar;
import com.stockz.equity.pattern.Child;

@Component
public class ClearDrawingButton extends JButton implements Child, Ordered {
	private static final long serialVersionUID = -5105536001583461308L;

	@SuppressWarnings("unchecked")
	private List<Class> parentList = new ArrayList<Class>(1);
	@Autowired StockChartView stockChartView;
	
	public ClearDrawingButton(){
		super(new ImageIcon(new ImageIcon("src/com/stockz/equity/resource/image/clear.jpg")
		.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)));
		parentList.add(DrawingToolbar.class);
		addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				stockChartView.getSelectedStockChart().getStockChartPanel()
				.getStockChartPanelState().getShapeSet().clear();
				EventPublisher.publishEvent(
						new RepaintStockChartPanelEvent(
								stockChartView.getSelectedStockChart().getStockChartPanel()));
			}
			
		});
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Collection<Class> getParents() {
		return parentList;
	}

	@Override
	public int getOrder() {
		return 2;
	}
}
